package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysAppPrescriptioninfoMedicine;
import com.ruoyi.system.service.ISysAppPrescriptionInfoService;
import com.ruoyi.system.service.ISysAppPrescriptioninfoMedicineService;

/**
 * 方剂与药物关联关系Controller
 * 
 * @author ruoyi
 * @date 2020-10-11
 */
@Controller
@RequestMapping("/system/prescriptioninfomedicine")
public class SysAppPrescriptioninfoMedicineController extends BaseController {
	private String prefix = "system/prescriptioninfomedicine";

	@Autowired
	private ISysAppPrescriptioninfoMedicineService sysAppPrescriptioninfoMedicineService;

	@Autowired
	private ISysAppPrescriptionInfoService sysAppPrescriptionInfoService;

	@RequiresPermissions("system:medicine:view")
	@GetMapping()
	public String medicine() {
		return prefix + "/medicine";
	}

	/**
	 * 查询方剂与药物关联关系列表
	 */
	@RequiresPermissions("system:medicine:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysAppPrescriptioninfoMedicine sysAppPrescriptioninfoMedicine) {
		startPage();
		List<SysAppPrescriptioninfoMedicine> list = sysAppPrescriptioninfoMedicineService
				.selectSysAppPrescriptioninfoMedicineList(sysAppPrescriptioninfoMedicine);
		return getDataTable(list);
	}

	/**
	 * 导出方剂与药物关联关系列表
	 */
	@RequiresPermissions("system:medicine:export")
	@Log(title = "方剂与药物关联关系", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(SysAppPrescriptioninfoMedicine sysAppPrescriptioninfoMedicine) {
		List<SysAppPrescriptioninfoMedicine> list = sysAppPrescriptioninfoMedicineService
				.selectSysAppPrescriptioninfoMedicineList(sysAppPrescriptioninfoMedicine);
		ExcelUtil<SysAppPrescriptioninfoMedicine> util = new ExcelUtil<SysAppPrescriptioninfoMedicine>(
				SysAppPrescriptioninfoMedicine.class);
		return util.exportExcel(list, "medicine");
	}

	/**
	 * 新增方剂与药物关联关系
	 */
	@GetMapping("/add/{prescriptionInfoId}")
	public String add(@PathVariable("prescriptionInfoId") Long prescriptionInfoId, ModelMap mmap) {
		mmap.put("prescriptionInfo",
				sysAppPrescriptionInfoService.selectSysAppPrescriptionInfoById(prescriptionInfoId));
		return prefix + "/add";
	}

	/**
	 * 新增保存方剂与药物关联关系
	 */
	@RequiresPermissions("system:medicine:add")
	@Log(title = "方剂与药物关联关系", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SysAppPrescriptioninfoMedicine sysAppPrescriptioninfoMedicine) {
		return toAjax(sysAppPrescriptioninfoMedicineService
				.insertSysAppPrescriptioninfoMedicine(sysAppPrescriptioninfoMedicine));
	}

	/**
	 * 修改方剂与药物关联关系
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppPrescriptioninfoMedicine sysAppPrescriptioninfoMedicine = sysAppPrescriptioninfoMedicineService
				.selectSysAppPrescriptioninfoMedicineById(id);
		mmap.put("sysAppPrescriptioninfoMedicine", sysAppPrescriptioninfoMedicine);
		return prefix + "/edit";
	}

	/**
	 * 修改保存方剂与药物关联关系
	 */
	@RequiresPermissions("system:medicine:edit")
	@Log(title = "方剂与药物关联关系", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SysAppPrescriptioninfoMedicine sysAppPrescriptioninfoMedicine) {
		return toAjax(sysAppPrescriptioninfoMedicineService
				.updateSysAppPrescriptioninfoMedicine(sysAppPrescriptioninfoMedicine));
	}

	/**
	 * 删除方剂与药物关联关系
	 */
	@RequiresPermissions("system:medicine:remove")
	@Log(title = "方剂与药物关联关系", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sysAppPrescriptioninfoMedicineService.deleteSysAppPrescriptioninfoMedicineByIds(ids));
	}
}
